﻿using AutoMapper;
using MediatR;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.BatchManagements
{
    public class TareSetCreateHander : IRequestHandler<TareSetCreateCommand, Resqults>
    {
        private readonly IBateRepository<TareSet> tareset;
        private readonly IMapper mapper;

        public TareSetCreateHander(IBateRepository<TareSet> tareset, IMapper mapper)
        {
            this.tareset = tareset;
            this.mapper = mapper;
        }

        public async Task<Resqults> Handle(TareSetCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults res=new Resqults() { Code=0};
                TareSet set=mapper.Map<TareSet>(request);
                res.Code = await tareset.Add(set);
                if (res.Code > 0)
                {
                    res.Messges = "添加成功";
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
